{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "381205a0-b382-4ac8-b45b-30d966b0821a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入x： 3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.0 的算术平方根= 1.7320508075688772\n"
     ]
    }
   ],
   "source": [
    "#求 a 的算术平方根的近似方法\n",
    "def sqrtA( a ):\n",
    "    if a<=0:\n",
    "        return 0\n",
    "    x0 = a;x1 = (x0 + a / x0) / 2\n",
    "    while (abs(x1 - x0) > pow(10, -6)):\n",
    "        x0 = x1; x1 = (x0 + a / x0) / 2\n",
    "    return x1\n",
    "#测试代码\n",
    "a = float(input(\"请输入x：\"))\n",
    "print( a,\"的算术平方根=\",sqrtA( a ))\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a979016c-4b79-4e80-b0ad-65ddc5dbda44",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
